package com.alit.face.koala.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alit.face.koala.data.KoalaCemaraType;
import com.alit.face.koala.entity.KoalaCemara;
import com.alit.face.koala.mq.apacheapollo.MQTTSender;
import com.alit.face.koala.websocket.NotifyWebSocket;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class KoalaMqService {
  @Autowired
  private NotifyWebSocket notityWebSocket;

  public void sendMessage(KoalaCemara koalaCemara, String message) {
    String type = koalaCemara.getType();
    String topic = koalaCemara.getTopic();
    if (KoalaCemaraType.websocket.equals(type)) {
      notityWebSocket.sendText(topic, message);
    } else {
      MQTTSender.send(topic, message);
    }
    log.info("发送消息:" + type + "," + topic + "," + message);
  }
}
